@page "/test-auth"
@using Microsoft.AspNetCore.Components.Authorization
@inject AuthenticationStateProvider AuthenticationStateProvider

<PageTitle>Test Auth</PageTitle>

<h1>认证测试页面</h1>

<AuthorizeView>
    <Authorized>
        <p>您已认证，用户: @context.User.Identity.Name</p>
    </Authorized>
    <NotAuthorized>
        <p>您未认证</p>
    </NotAuthorized>
</AuthorizeView>

@code {
    protected override async Task OnAfterRenderAsync(bool firstRender)
    {
        if (firstRender)
        {
            try
            {
                var authState = await AuthenticationStateProvider.GetAuthenticationStateAsync();
                Console.WriteLine($"TestAuth页面获取认证状态: {authState.User.Identity.IsAuthenticated}, 用户: {authState.User.Identity.Name}");
            }
            catch (Exception ex)
            {
                Console.WriteLine($"TestAuth页面获取认证状态时发生错误: {ex.Message}");
            }
        }
    }
}